package com.qingke.Qiximybatis.command;

import java.util.HashMap;
import java.util.Map;
import com.qingke.Qiximybatis.business.Exit14;
import com.qingke.Qiximybatis.business.HelpCommand;
import com.qingke.Qiximybatis.business.Login;
import com.qingke.Qiximybatis.business.Register;
import com.qingke.Qiximybatis.command.CommandFactory.CommandCode;

public class SystemCommandFactory extends CommandFactory {
	
	private static Map<CommandCode,Class<? extends Command>> commandMap = new HashMap<>();
	
	static{
		commandMap.put(CommandCode.EXIT,  Exit14.class);
		commandMap.put(CommandCode.HELP,  HelpCommand.class);
		commandMap.put(CommandCode.LOGIN, Login.class);
		commandMap.put(CommandCode.REGISTER, Register.class);
	}
	
	public Command buildCommand(CommandCode cmdCode){
		Class<? extends Command> cmdClass = commandMap.get(cmdCode);
		
		if(cmdClass != null){
			try{
				return cmdClass.newInstance();
			}catch(InstantiationException | IllegalAccessException e){
				 e.printStackTrace();
			}
		}
		return null;
	}
}
